package com.learn.springlearn.config;

import com.google.common.util.concurrent.ThreadFactoryBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.*;

@Configuration
public class ExecutorConfig {

    @Bean(name = "taskExecutorPool")
    public Executor taskExecutorPool() {
        int corePoolSize = Runtime.getRuntime().availableProcessors();

        ThreadFactory factory = new ThreadFactoryBuilder().setNameFormat("task-pool-%d").build();

        return new ThreadPoolExecutor(corePoolSize, corePoolSize * 6, 1, TimeUnit.MINUTES, new LinkedBlockingDeque<>(100),
                factory, new ThreadPoolExecutor.AbortPolicy());
    }
}
